package com.hnevc.xiaoming.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hnevc.xiaoming.R;
import com.hnevc.xiaoming.bean.MyWeatherBean;

import java.util.List;

public class MyWeatherRvAdapter extends RecyclerView.Adapter<MyWeatherRvAdapter.MyViewHolder> {

    private Context context;
    private List<MyWeatherBean.ResultBean.FutureBean> list;
    private String wt;

    public MyWeatherRvAdapter(Context context, List<MyWeatherBean.ResultBean.FutureBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.weather_itme, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

        MyWeatherBean.ResultBean.FutureBean resultBean = list.get(position);
        holder.rv_itme_date.setText("日期: "+resultBean.getDate());
        holder.rv_itme_temperature.setText("温度: "+resultBean.getTemperature());

        String weather = resultBean.getWeather();
        holder.rv_itme_weather.setText("天气:"+ weather);
        holder.rv_itme_direct.setText("风向: "+resultBean.getDirect());
        wt = "lightrain";
        switch (weather){
            case "小雨":
                wt ="lightrain";
                break;
            case "中雨":
                wt ="moderaterain";
                break;
            case "多云":
                wt ="partlycloudy";
                break;
            case "多云转晴":
                wt ="cloudytoovercast";
                break;
            case "晴":
                wt ="clear";
                break;
             case "阴天":
                wt ="cloudyday";
                break;
            case "阴转小雨":
                wt ="cloudytolightrain";
                break;
        }
        int img = context.getResources().getIdentifier(wt, "mipmap" , context.getPackageName());
        holder.rv_itme_imge.setImageResource(img);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView rv_itme_date;
        private TextView rv_itme_temperature;
        private TextView rv_itme_weather;
        private TextView rv_itme_direct;
        private ImageView rv_itme_imge;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            rv_itme_date = itemView.findViewById(R.id.rv_itme_date);
            rv_itme_temperature = itemView.findViewById(R.id.rv_itme_temperature);
            rv_itme_weather = itemView.findViewById(R.id.rv_itme_weather);
            rv_itme_direct = itemView.findViewById(R.id.rv_itme_direct);
            rv_itme_imge = itemView.findViewById(R.id.rv_itme_img);

        }
    }
}
